package com.cms.controller;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor;

import com.cms.entity.Article;
import com.cms.entity.Comment;
import com.cms.service.ArticleService;
import com.cms.service.CommentService;
import com.cms.util.ResponseUtil;

import net.sf.json.JSONObject;

@Controller
@RequestMapping("/comment.do")
public class CommentController {

	@Resource
	private CommentService commentService;
	
	@Resource
	private ArticleService articleService;
	
	@RequestMapping("/{articleId}")
    public String addComment(String content, @PathVariable("articleId") Integer articleId){
		Comment comment = new Comment();
		comment.setContent(content);
		comment.setAid(articleId);
		
		
		Article article = articleService.findById(articleId);
		comment.setArticle(article);
		comment.setDate(new Date());
		System.out.println("commentController" + comment.toString());
		commentService.add(comment);
		return null;
    }


}
